package com.ggk911.pharmacy_system.config;

import com.ggk911.pharmacy_system.interceptor.MyInterceptor;
import com.ggk911.pharmacy_system.util.JWTUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置
 *
 * @author ggk-911
 * @version 1.0 2023/2/24 14:22
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
public class InterceptorConfig implements WebMvcConfigurer {
    private final JWTUtil jwtUtil;

    @Bean
    public MyInterceptor myInterceptor() {
        return new MyInterceptor(jwtUtil);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //重写拦截规则
        registry.addInterceptor(myInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/error")
                .excludePathPatterns("/user/verifyToken")
//                .excludePathPatterns("/drug/importExcel")
//                .excludePathPatterns("/supplier/importExcel")
//                .excludePathPatterns("/supplierDrug/importExcel")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/v3/**", "/swagger-ui/**");
    }

}
